package com.pine.dao.pineframework.constants;

import com.baomidou.mybatisplus.annotation.EnumValue;
import com.pine.common.beans.enums.IntegerCodeBaseEnum;
import com.pine.common.database.constant.DbDataScopeEnum;
import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Arrays;
import java.util.Objects;

/**
 * <p>
 * 角色表-数据权限 枚举
 * </p>
 *
 * @author pine manage
 * @since 2024-08-12
 */
@AllArgsConstructor
@Getter
public enum DataScopeEnum implements IntegerCodeBaseEnum {
    ALL(DbDataScopeEnum.ALL.getCode(), DbDataScopeEnum.ALL.getDesc()),
    DEPT_WITH_CHILDREN(DbDataScopeEnum.DEPT_WITH_CHILDREN.getCode(), DbDataScopeEnum.DEPT_WITH_CHILDREN.getDesc()),
    DEPT(DbDataScopeEnum.DEPT.getCode(), DbDataScopeEnum.DEPT.getDesc()),
    ONLY_SELF(DbDataScopeEnum.ONLY_SELF.getCode(), DbDataScopeEnum.ONLY_SELF.getDesc()),
    ;

    @EnumValue
    private final Integer code;
    private final String desc;

    public static DataScopeEnum of(Integer code) {
        return Arrays.stream(DataScopeEnum.values()).filter(dataScopeEnum -> Objects.equals(dataScopeEnum.code, code)).findAny().orElse(null);
    }
}
